package edu.towson.cosc603.coffeemaker;

import junit.framework.TestCase;

/**
 *
 */
public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1;

	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
	}

	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
	}
	public void testAddRecipe2(){
		Recipe r2 = new Recipe();
		r2.setName("Coffee");
		r2.setPrice(50);
		r2.setAmtCoffee(6);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(0);
		cm.addRecipe(r2);
		assertFalse(cm.addRecipe(r2));
		
	}

	public void testDeleteRecipe1() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}

	public void testEditRecipe1() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
	}
	public void testAddInventory(){
		
		assertTrue(cm.addInventory(3,4,5,6));
	}
	public void testAddInventory2(){
		assertFalse(cm.addInventory(-1,-1,-1,-1));
		
	}
	public void testMakeCoffee(){
		cm.addRecipe(r1);
		
		int r = cm.makeCoffee(r1,50);
		assertEquals(r,0);
		
	}
	/**
	 * testMakeCoffee2 will return the change
	 * if there is not enough money entered
	 * to make the recipe
	 */
	public void testMakeCoffee2(){
		cm.checkInventory();
		
		cm.addInventory(1,1,1,1);
		Recipe r2 = new Recipe();
		r2.setName("Coffee2");
		r2.setPrice(50);
		r2.setAmtCoffee(76);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(0);
		cm.addRecipe(r2);
		cm.makeCoffee(r2,30);
		assertNotSame(cm.makeCoffee(r2,50),0);
		int change = cm.makeCoffee(r2,50);
		System.out.println("Change returned is:"+change);
		
	}
	public void testMakeCoffee3(){
		cm.addInventory(6,1,1,1);
		Recipe r2 = new Recipe();
		r2.setName("Coffee2");
		r2.setPrice(50);
		r2.setAmtCoffee(6);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(0);
		cm.addRecipe(r2);
		cm.makeCoffee(r2,30);
		assertNotSame(cm.makeCoffee(r2,40),0);
		int change = cm.makeCoffee(r2,40);
		System.out.println("Change returned is:"+change);
	}
	
	public void testGetRecipes(){
		cm.addRecipe(r1);
		Recipe r2 = new Recipe();
		r2.setName("Coffee2");
		r2.setPrice(50);
		r2.setAmtCoffee(6);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(0);
		cm.addRecipe(r2);
		Recipe[] rs = cm.getRecipes();
		assertNotNull(rs);
	}
	
	public void testGetRecipeForName(){
		Recipe r3 = new Recipe();
		r3.setName("Capp");
		cm.addRecipe(r3);
		Recipe rCheck = cm.getRecipeForName("Capp");
		assertEquals(rCheck.getName(),"Capp");
	}
}